using System;
using System.Collections.Generic;
using System.Text;
using TVProgram.Base;
using System.Net;
using System.IO;
using System.Globalization;

namespace TVProgram.Channels
{
    class VTC7 : BaseChannel
    {
        public VTC7(DateTime CurDay, string channel)
        {
            this._name = channel;
            this._date = CurDay;
            string Day = Convert.ToString(this._date.Day);
            string Month = Convert.ToString(this._date.Month);
            string Year = Convert.ToString(this._date.Year);//http://www.todaytv.vn/lichchieu/1330707600/3-3-2012
            this._url = "http://www.todaytv.vn/lichchieu/1330707600/" + Day + "-" + Month + "-" + Year;
        }

        public override void GetTextFromHtml(string html)
        {

            //string stra = "<td class=\"tdFormRow\" align=\"center\">";
            string str1 = "align=absmiddle border=0 height=38 width=15><b>";
            string str2 = "</b>";
            int curIndex = 0;

            while (true)
            {
                curIndex = html.IndexOf(str1, curIndex);
                if (curIndex == -1)
                    break;
                curIndex = html.IndexOf(str1, curIndex);
                int startIndex = curIndex + str1.Length;

                curIndex = html.IndexOf(str2, startIndex);
                if (curIndex == -1)
                    break;
                int endIndex = curIndex;

                string StrTime = html.Substring(startIndex, endIndex - startIndex);
                string strHour = StrTime.Substring(0, 2);
                int Hour = Convert.ToInt32(strHour);
                if (Hour > 23)
                    break;
                curIndex += str2.Length;

                //string strb = "td class=\"tdFormRow";
                string str3 = "<div style=\"width:25%;float:left;\"><img src=\"/images/spacer.gif\" align=absmiddle border=0 height=38 width=1>";
                string str4 = "</div>";

                curIndex = html.IndexOf(str3, curIndex);
                if (curIndex == -1)
                    break;
                startIndex = curIndex + str3.Length;

                curIndex = html.IndexOf(str4, startIndex);
                if (curIndex == -1)
                    break;
                endIndex = curIndex;
                curIndex += str4.Length;
                string StrTitle1 = html.Substring(startIndex, endIndex - startIndex);

                string str5 = "<div style=\"width:60%;float:left;\"><img src=\"/images/spacer.gif\" align=absmiddle border=0 height=38 width=1><b class=bshow>";
                string str6 = "</b>";

                curIndex = html.IndexOf(str5, curIndex);
                if (curIndex == -1)
                    break;
                startIndex = curIndex + str5.Length;

                curIndex = html.IndexOf(str6, startIndex);
                if (curIndex == -1)
                    break;
                endIndex = curIndex;
                curIndex += str6.Length;
                string StrTitle2 = html.Substring(startIndex, endIndex - startIndex);
                string StrTitle = StrTitle1 + ": " + StrTitle2;

                ProgramItem item = new ProgramItem();
                item.StartTime = item.GetDateTimeFromString(StrTime);
                item.Content = StrTitle;
                this._items.Add(item);
            }

        }
    }
}

